package org.yscz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yscz.entity.Project;
import org.yscz.entity.ProjectType;
import org.yscz.mapper.ProjectMapper;
import org.yscz.mapper.ProjectTypeMapper;
import org.yscz.service.ProjectService;

import java.util.Date;
import java.util.List;

/**
 * @author muqs
 * @create 2021-08-18 17:48
 */
@Service
@Slf4j
public class ProjectServiceImpl implements ProjectService {

    @Autowired
    private ProjectMapper projectMapper;

    @Autowired
    private ProjectTypeMapper projectTypeMapper;

    @Override
    public Project add(Project project) {
        project.setCreateTime(new Date());
        projectMapper.insert(project);
        return project;
    }

    @Override
    public void modify(Project project) {
        project.setUpdateTime(new Date());
        projectMapper.updateById(project);
    }

    @Override
    public void del(Long projectId) {
        projectMapper.deleteById(projectId);
    }

    @Override
    public IPage<Project> listPage(QueryWrapper queryWrapper, IPage<Project> page) {
        return projectMapper.selectPage(page, queryWrapper);
    }

    @Override
    public List<ProjectType> projectTypeList(QueryWrapper queryWrapper) {
        return projectTypeMapper.selectList(queryWrapper);
    }
}
